#include"stdio.h"

int gcd(int a,int b)
{
    int z;
    while(b)
    {
        z = a%b;
        a = b;
        b =z;
    }
    return a;
}

int main()
{
    int p , q , r;
    while(scanf("%d %d",&p,&q) != EOF)
    {
        if(p > q) {r = p;p = q;q = r;}
        r = gcd(p,q);
        p/=r;q/=r;
        printf("%d\n",(p+q-1)*r);
    }
    return 0;
}